//
// Created by de on 3/31/21.
//

#include "CSemaphore.h"

void CSemaphore::signal() {
    std::unique_lock<std::mutex> lock(_mutex);
    m_count = m_count + 1;
    _cv.notify_one();
}

void CSemaphore::wait()
{
    std::unique_lock<std::mutex> lock(_mutex);

    _cv.wait(lock, [=] {return m_count > 0; });
    m_count = m_count -1;

}

CSemaphore::CSemaphore() {
    m_count = 0;
}
